let actionCreator = (type, payload) => ({ type, payload });

export const SET_PRODUCTS = function(parm) {
    return function(dispatch) {
        fetch(`http://106.12.79.128:666/playlist/detail?id=${parm}`)
            .then(body => body.json())
            .then(res => {
                console.log(res);

                dispatch(actionCreator("SET_PRODUCTS", res));
            })
            .catch(err => {
                throw new Error(err);
            });
    };
};
export const GET_TOP = function(parm) {
    return function(dispatch) {
        fetch(`http://106.12.79.128:666/top/list?idx=${parm}`)
            .then(body => body.json())
            .then(res => {
                console.log(res);

                dispatch(actionCreator("SET_PRODUCTS", res));
            })
            .catch(err => {
                throw new Error(err);
            });
    };
};

export const SET_SONGER = function(parm) {
    return function(dispatch) {
        fetch(`http://106.12.79.128:666/artists?id=${parm}`)
            .then(body => body.json())
            .then(res => {
                console.log(res);

                dispatch(actionCreator("SET_SONGER", res));
            })
            .catch(err => {
                throw new Error(err);
            });
    };
};
